Skip to content

Conversation

@lukesmmr
Copy link
Member

@lukesmmr lukesmmr commented Feb 7, 2026

Summary by CodeRabbit

  • New Features

    • Added seed script to easily populate the database with 17 sample disaster records for testing.
  • Bug Fixes

    • Disaster count calculations now correctly respect filtering by status, type, and date range.
  • Tests

    • Added comprehensive GraphQL API tests covering filtering, pagination, and combined filter scenarios.
  • Documentation

    • Added seeding setup instructions and database reset guidance to README.

lukesmmr and others added 3 commits February 7, 2026 17:25
countDisasters() previously ignored all filters (type, status, dateFrom,
dateTo) and always returned the total row count. The GraphQL disasters
query now returns accurate total and totalPages for filtered results.

Co-authored-by: Cursor <cursoragent@cursor.com>
Three new tests verify that total and totalPages reflect the applied
filters (status, type, and combined pagination + filter) rather than
the unfiltered row count.

Co-authored-by: Cursor <cursoragent@cursor.com>
Single TypeScript script (npm run seed) that populates the API via the
bulk insert endpoint. Covers 6 continents, 12 disaster types, dates
spanning Jan 2025 – Feb 2026, and all three statuses.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

Added seeding infrastructure to populate the database with sample disaster data via a new npm script, enhanced the disasters GraphQL query to respect filters when calculating totals and pagination, and introduced comprehensive tests validating filtering and pagination behavior.

Changes

Cohort / File(s) Summary
Seeding Infrastructure
scripts/seed.ts, package.json
New seed script that POSTs 17 predefined disasters to the bulk API endpoint, with configurable base URL support. Added npm run seed command for easy execution.
Service Layer
services/disaster.service.ts
Updated countDisasters function to accept an optional DisasterFilter parameter and build dynamic WHERE clauses based on type, status, dateFrom, and dateTo fields.
GraphQL Query
graphql/resolvers.ts
Modified disasters query to pass the constructed filter to countDisasters, ensuring total and totalPages reflect filtered results rather than full dataset counts.
Testing
graphql/graphql.test.ts
Added 120 lines of comprehensive test coverage for status-based filtering, type-based filtering, pagination interactions, and combined filter scenarios with data seeding and assertion validation.
Documentation
README.md
Added "Seeding Sample Data" section describing the seed script, three invocation variants (docker, host, custom URL), additive behavior, and database reset instructions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Seeds are sown in the database ground,
Filtered queries spin round and round,
Tests now verify each sorted row,
Disasters counted—swift they grow!
A burrow of code, refined and sound! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the two main changes: fixing the GraphQL filtered count issue and adding a seed script.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/graphql-filtered-count-and-seed-script

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
services/disaster.service.ts (1)

91-117: Duplicated filter-building logic with getAllDisasters.

The WHERE-clause construction (lines 92–111) is nearly identical to lines 46–69 in getAllDisasters. Consider extracting a shared helper, e.g.:

function buildFilterClause(filter: DisasterFilter, startIndex = 1) {
  const conditions: string[] = [];
  const values: unknown[] = [];
  let paramIndex = startIndex;
  if (filter.type) { conditions.push(`type = $${paramIndex++}`); values.push(filter.type); }
  if (filter.status) { conditions.push(`status = $${paramIndex++}`); values.push(filter.status); }
  if (filter.dateFrom) { conditions.push(`date >= $${paramIndex++}::timestamp`); values.push(filter.dateFrom); }
  if (filter.dateTo) { conditions.push(`date <= $${paramIndex++}::timestamp`); values.push(filter.dateTo); }
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
  return { whereClause, values, paramIndex };
}

This eliminates the duplication and ensures both functions stay in sync when new filter fields are added.

scripts/seed.ts (1)

157-182: Add a top-level catch to main() for network errors.

If the server is unreachable, fetch throws a TypeError and the process exits with an unhandled rejection and a cryptic message. A catch on main() would give a friendlier diagnostic:

Suggested fix
-main();
+main().catch((err) => {
+  console.error('Seed failed:', err.message ?? err);
+  process.exit(1);
+});

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lukesmmr
Copy link
Member Author

lukesmmr commented Feb 7, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lukesmmr lukesmmr requested a review from caspear February 8, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant